namespace Digitalmes.Common.Workflows;

/// <summary>
/// 工作流步骤连线构建器。
/// </summary>
public sealed class WorkflowEdgeBuilder
{
    /// <summary>
    /// 边缘线触发的事件 Id。
    /// </summary>
    internal string EventId { get; }

    /// <summary>
    /// 边缘线连接节点。
    /// </summary>
    internal WorkflowStepBuilder Source { get; }

    /// <summary>
    /// 边缘的目标方法节点，null 表示没有下一节点。
    /// </summary>
    internal WorkflowFunctionTargetBuilder? Target { get; set; }

    internal WorkflowEdgeBuilder(WorkflowStepBuilder source, string eventId)
    {
        Source = source;
        EventId = eventId;
    }

    internal WorkflowEdge Build()
    {
        //return new WorkflowEdge(Source.Id, Target.Id);
        throw new NotImplementedException();
    }

    /// <summary>
    /// 链接到下一流程步骤。
    /// </summary>
    /// <param name="step">下一步要执行的流程步骤。</param>
    /// <param name="functionName">步骤中要指定的方法名称，为 null 表示</param>
    /// <param name="parameterName">方法参数，null 表示不指定参数。</param>
    /// <returns></returns>
    public WorkflowEdgeBuilder SendEventTo(WorkflowStepBuilder step, string? functionName, string? parameterName = null)
    {
        Target = new(step, functionName, parameterName);
        Source.LinkTo(EventId, this);
        return new WorkflowEdgeBuilder(Source, EventId);
    }
}
